package com.cdream.basic.algorithm.leetcode.linkedlist;

/**
 * @author cdream
 * @date 6/15/21
 */
public class Question852 {
    public int peakIndexInMountainArray(int[] arr) {
        return findMaxHeightIndex(arr, 1, arr.length - 2);
    }

    private int findMaxHeightIndex(int[] arr, int left, int right) {
        if(left == right){
            return left;
        }
        int mid = left + (right-left)/2;
        int last = arr[mid-1];
        int midNum = arr[mid];
        if(midNum < last){
            return findMaxHeightIndex(arr,left,mid-1);
        }else {
            return findMaxHeightIndex(arr,mid,right);
        }

    }

    public static void main(String[] args) {
        int i = new Question852().peakIndexInMountainArray(new int[]{0,2,1,0});
    }
}
